package cn.hc.tool.exec.controller;

import cn.hc.tool.exec.aspect.Administrators;
import cn.hc.tool.exec.bean.MethodRes;
import cn.hc.tool.exec.service.HcScanService;
import com.hc.json.adapter.Json;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/9/24 20:38
 */
@Controller
@RequestMapping("/test/scan")
@Slf4j
@ResponseBody
@Administrators
public class HcScanController {

    @Autowired
    private HcScanService hcScanService;

    @RequestMapping({"/has", "/has.html", "/has.json"})
    public String containsMethod(String pkgs, String fields) {
        MethodRes res = hcScanService.getMethodsByPkgsAndFields(Arrays.asList(pkgs.split(",")), Arrays.asList(fields.split(",")));
        Map<String, String> result = new HashMap<String, String>();
        result.put("reqMethod", res.getReqMethod().toString());
        result.put("returnMethod", res.getReturnMethod().toString());
        result.put("maybeMethod", res.getMaybeMethod().toString());
        return Json.toJson(result);
    }
}
